<?php
session_start();

if(isset($_SESSION['authorised']) && $_SESSION['authorised'] == true)
{   
    if(isset($_SESSION['type']))
    {
        if($_SESSION['type'] == 'administrator')
        {
            header('Location: admin_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'student')
        {
            header('Location: student_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'tutor')
        {
            header('Location: tutor_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'parent')
        {
            include('connection.inc');
            $username= $_SESSION['user']; 
			$comments=addslashes(pg_escape_string($_POST['comments']));

            $sql="INSERT INTO feedbacks (feedback, feedback_date, username) VALUES ('$comments', localtimestamp, '$username')";
            $result = pg_query($sql);
            
			$_SESSION['message'] = "Thank you for sending us a message!";	
			header('Location: parent_contactadmin.php');
			exit();
        }
    }
}
else
{
    header('Location: index.php');
}
?>
